home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 7.5 KB | 236 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Hello.hpp"
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfhello
- #endif
-
- FW_DEFINE_AUTO(CHelloContent)
-
- //========================================================================================
- // CHelloContent class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CHelloContent constructor
- //----------------------------------------------------------------------------------------
-
- CHelloContent::CHelloContent(Environment* ev, CHelloPart* part) :
- FW_CContent(ev, part),
- fTextData(""),
- fCentered(FALSE),
- fHelloPart(part)
- {
- // ----- Initialize the text data strings -----
- FW_CSharedLibraryResourceFile resFile(ev);
-
- FW_CString32 platformString;
- ::FW_LoadStringByID(ev, resFile, kHelloPartStrings, MULTISTRINGRES, kFirstString, fTextData);
- ::FW_LoadStringByID(ev, resFile, kHelloPartStrings, MULTISTRINGRES, kPlatformString, platformString);
- fTextData += platformString;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent destructor
- //----------------------------------------------------------------------------------------
-
- CHelloContent::~CHelloContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::GetTextData
- //----------------------------------------------------------------------------------------
-
- const FW_CString& CHelloContent::GetTextData()
- {
- return fTextData;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::SetTextData
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::SetTextData(Environment* ev, const FW_CString& newText)
- {
- fTextData = newText;
- fHelloPart->PartChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::ClearTextData
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::ClearTextData(Environment* ev)
- {
- /* FW_CString32 newString; [MEB] Jim - reveals bug in Strings when trying to ReplaceAll with a string that's too big */
- FW_CString newString;
- FW_CSharedLibraryResourceFile resFile(ev);
- ::FW_LoadStringByID(ev, resFile, kHelloPartStrings, MULTISTRINGRES, kBlankString, newString);
-
- fTextData = newString;
- fHelloPart->PartChanged(ev); // Notify the proper authorities
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::Externalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
-
- ExternalizePartKind(ev, storageUnit);
-
- if (storageKind != FW_kPartStorage)
- ExternalizeText(ev, storageUnit);
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::ExternalizePartKind
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::ExternalizePartKind(Environment* ev, ODStorageUnit* storageUnit)
- {
- // Write the two text data strings to storage
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fHelloPart->GetPartKind(ev));
- FW_CWritableStream archive(suSink);
- unsigned long stringCount = 1;
-
- archive << stringCount;
- archive << fCentered;
- archive << fTextData;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::ExternalizeText
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::ExternalizeText(Environment* ev, ODStorageUnit* destinationSU)
- {
- #ifdef FW_BUILD_MAC
- // Also write the string in text format
- FW_SUAddPropValue(ev, destinationSU, kODPropContents, FW_CPart::gMacTEXTDataType);
- FW_PStorageUnitSink suSink(ev, destinationSU, kODPropContents, FW_CPart::gMacTEXTDataType);
- FW_CWritableStream stream(suSink);
- stream.Write(fTextData.RevealBuffer(), fTextData.GetByteLength());
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::Internalize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloContent::Internalize(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
- FW_Boolean internalized = FALSE;
-
- if (FW_SUExistsThenFocus(ev, sourceSU, kODPropContents, fHelloPart->GetPartKind(ev)))
- internalized = this->InternalizePartKind(ev, sourceSU);
- #ifdef FW_BUILD_MAC
- else if (FW_SUExistsThenFocus(ev, sourceSU, kODPropContents, FW_CPart::gMacTEXTDataType)) // 'TEXT'
- internalized = this->InternalizeText(ev, sourceSU);
- #endif
-
- if (internalized && storageKind != FW_kPartStorage)
- fHelloPart->PartChanged(ev);
-
- return internalized;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::InternalizeText
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloContent::InternalizeText(Environment* ev, ODStorageUnit* storageUnit)
- {
- FW_Boolean result = FALSE;
-
- #ifdef FW_BUILD_MAC
- unsigned long textSize = storageUnit->GetSize(ev);
- if (textSize > 0)
- {
- char buffer[256];
- if (textSize > 255)
- textSize = 255;
- FW_CByteArray byteArray;
- storageUnit->GetValue(ev, textSize, byteArray);
- byteArray.CopyBuffer(&buffer, textSize);
-
- fTextData = "";
- fTextData.Append((const FW_Char*) &buffer, textSize);
-
- result = TRUE;
- }
- #endif
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::InternalizePartKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloContent::InternalizePartKind(Environment* ev, ODStorageUnit* storageUnit)
- {
- FW_Boolean internalized = TRUE;
-
- if (storageUnit->GetSize(ev) != 0)
- {
- // Read the text data strings from storage
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fHelloPart->GetPartKind(ev));
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream archive(sink);
-
- unsigned long stringCount;
- archive >> stringCount;
- archive >> fCentered;
- if (stringCount > 0)
- archive >> fTextData;
- }
-
- return internalized;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloContent::CenterText
- //----------------------------------------------------------------------------------------
-
- void CHelloContent::CenterText(Environment* ev, FW_Boolean state)
- {
- fCentered = state;
- fHelloPart->PartChanged(ev);
- }
-
-